using System;
using ilgolosone.Shared.Configuration;

namespace ilgolosone.Shared
{
    public static class Bootstrapper
    {
        private static readonly object _locker = new object();
        private static IBootstrapper _bootstrapper;

        static void Init()
        {
            lock (_locker)
            {
                if (_bootstrapper != null) return;

                Type type = Type.GetType(DependencyResolverConfiguration.Instance.BootstrapType);

                if (type == null) throw new ApplicationException("Non trovo l'implementazione IoC da utilizzare");

                _bootstrapper = (IBootstrapper)Activator.CreateInstance(type);
            }
        }

        public static void Initialize()
        {
            Init();
            _bootstrapper.Init();
        }
    }
}